package com.quxueba.index.dal;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.quxueba.index.model.Product;
import com.quxueba.index.model.School;
import com.quxueba.index.model.User;

//@Transactional
@Repository("AppDao")
public class AppDaoImpl implements AppDao {
	
//	public AppDaoImpl() {
//		
//	}

//	@Autowired
//	@Qualifier("sessionFactory")
//	@SuppressWarnings("unchecked")
//	@Resource("sessionFactory")
//	public SessionFactory sessionFactory;
	
	@Autowired
//    @Qualifier("sessionFactory")
//	@Resource(name="sessionFactory")
    protected SessionFactory sessionFactory;
    public void setSessionFactory(SessionFactory sessionFactory) {
    	this.sessionFactory = sessionFactory;
    }
    public SessionFactory getSessionFactory() {
    	return sessionFactory;
    }
    
//	protected Session session;
//	public void setSession(Session session) {
//    	this.session = session;
//    }
    public Session getSession() {
//    	return session;
    	return sessionFactory.getCurrentSession();
    }
	
//	public Session session = sessionFactory.getCurrentSession();
	
//	@Override
	public List<User> ff() {
//		System.out.println(session);
//		SessionFactory sessionFactory = this.sessionFactory;
		System.out.println("session");
		Query query = getSession().createQuery("from User");
		List<User> list = query.list();
		return list;
	}
	
	public List<School> getSchool() {
//		System.out.println(session);
//		SessionFactory sessionFactory = this.sessionFactory;
		System.out.println("session");
		Query query = getSession().createQuery("from School");
		List<School> list = query.list();
		return list;
	}
	
	public List<Product> getProduct() {
		Query query = getSession().createQuery("from Product");
		List<Product> list = query.list();
		return list;
	}
}
